class_name AnomalyState
extends Node2D


enum Type
{
    NONE,
    COMBUSTION,
    FREEZE,
    PALSY,
}


@export var type: Type
@export_multiline var description: String
@export var icon: Texture2D
@export var duration: float

@warning_ignore("unused_private_class_variable")
@onready var _target: Character = get_parent().get_parent()

var _done: bool = true
var _start_time: int


signal finished()


func _process(_delta: float) -> void:
    if _done: return
    if Time.get_ticks_msec() - _start_time >= duration * 1000:
        stop()
        return
    
    _effect()
    

## 虚函数
func _init_data() -> void:
    pass


## 虚函数，实现异常状态的效果
func _effect() -> void:
    pass


## 虚函数，异常状态结束时执行
func _end() -> void:
    pass


func start() -> void:
    _done = false
    _start_time = Time.get_ticks_msec()
    _init_data()


func stop() -> void:
    _end()
    _done = true
    finished.emit()


## 静态函数，获取伤害属性对应的异常类型
static func get_type(attr: DamageInfo.DamageAttribute) -> Type:
    match attr:
        DamageInfo.DamageAttribute.FIRE: return Type.COMBUSTION
        DamageInfo.DamageAttribute.ICE: return Type.FREEZE
        DamageInfo.DamageAttribute.THUNDER: return Type.PALSY
    return Type.NONE


## 静态函数，获取异常类型对应的伤害属性
static func get_damage_attribute(type_: Type) -> DamageInfo.DamageAttribute:
    match type_:
        Type.COMBUSTION: return DamageInfo.DamageAttribute.FIRE
        Type.FREEZE: return DamageInfo.DamageAttribute.ICE
        Type.PALSY: return DamageInfo.DamageAttribute.THUNDER
    return DamageInfo.DamageAttribute.NORMAL


## 静态函数，获取异常类型对应的字符串
static func get_type_str(type_: Type) -> String:
    match type_:
        Type.COMBUSTION: return "燃烧"
        Type.FREEZE: return "冻结"
        Type.PALSY: return "麻痹"
        _: return "无"


## 获取异常类型对应的字符串
func get_type_text() -> String:
    return get_type_str(type)


func get_damage_attr() -> DamageInfo.DamageAttribute:
    return get_damage_attribute(type)

